<?php
namespace app\admin\controller;
use think\Session;
use think\Db;
use app\common\controller\Backend;
class Xiangmu extends Backend{
	public function lists(){
        $list=Db::table('member_project')->paginate(12);
        $this->assign('list',$list);
		return $this->view->fetch();
	}
	public function edits(){
        $id=input('get.id');
        $data=array();
        if($id){
            $data=Db::table('member_project')->where('id', $id)->find();
        }
        $this->assign('data',$data);
        return $this->view->fetch();
	}

    public function save(){
        $data=$this->request->post();
        $admin = Session::get('admin');
        if(empty($data['id'])){
            $data['uid']= $admin['id'];
            $data['number']='p'.date('YmdHis');
            $data['time']=time();
            $re=Db::table('member_project')->insert($data);
        }else{
            $re=Db::table('member_project')->where('id', $data['id'])->update($data);
        }
        if($re!==false){
            $this->success(__('编辑成功'), 'lists');
        }else{
            $this->success(__('编辑失败'), 'lists');
        }
    }


    public function delete(){
        $id=input('get.id');
        $re=Db::table('member_project')->where('id',$id)->delete();
        if($re){
            $this->success(__('删除成功'), 'lists');
        }else{
            $this->success(__('删除失败'), 'lists');
        }
    }


    public function setting(){
        $id=input('post.id');
        $re=Db::table('member_baojia_info')->where('project_id',$id)->find();
        $this->result(['info' => $re],1,'返回成功','json');
    }

}